/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package vn.ac.c0910g.assignment.DAO;

import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import vn.ac.c0910g.assignment.Entity.Category;
import vn.ac.c0910g.assignment.Entity.CategoryFacade;

/**
 *
 * @author BachLe
 */
public class CategoryDAO {
    CategoryFacade categoryFacade = lookupCategoryFacadeBean();

    public CategoryDAO(){

    }

    private CategoryFacade lookupCategoryFacadeBean() {
        try {
            Context c = new InitialContext();
            return (CategoryFacade) c.lookup("java:global/Alluring_Decors/Alluring_Decors-ejb/CategoryFacade!vn.ac.c0910g.assignment.Entity.CategoryFacade");
        } catch (NamingException ne) {
            Logger.getLogger(getClass().getName()).log(Level.SEVERE, "exception caught", ne);
            throw new RuntimeException(ne);
        }
    }

    public List<Category> getAllCategory(){
        return this.categoryFacade.findAll();
    }

    public void addCategory(Category c){
        categoryFacade.create(c);
    }

    public void updateCategory(Category c){
        categoryFacade.edit(c);
    }

    public void deleteCategory(Category c){
        categoryFacade.remove(c);
    }
    
    public Category findCategoryById(String id){
        return categoryFacade.find(id);
    }
}
